<script setup name="Home">
import { onMounted } from 'vue';
import Logo from "@/assets/logo.png";
import {getToken, setToken, setUser} from "@/utils/auth.js";
import {getSnsToken} from "@/api/eyeCare.js";
import {useRouter, useRoute} from "vue-router";

const router = useRouter();
const route = useRoute();

onMounted(async () => {
  if (route.query.code) {
    if (!getToken()) {
      let resp = await getSnsToken(route.query.code)
      if (resp.code === 0) {
        setToken(resp.data)
        setUser(resp.data)
        await router.push("/patients")
      } else {
        await router.push("/home")
      }
    } else {
      setUser(getToken())
      await router.push("/patients")
    }
  }
})

</script>

<template>
  <div class="home">
    <van-image class="logo" width="100" height="100" :src="Logo" fit="cover" />
  </div>
</template>
<style lang="scss" scoped>
.home {
  display: flex;
  flex-direction: column;
  align-items: center;

  .logo {
    margin-top: 30px;
  }
}
</style>
